<!DOCTYPE html>
<html>
<head>
<title>商家登记</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="css/webuploader.css" />
<link rel="stylesheet" href="assets/css/amazeui.min.css" />
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="js/main.js"></script>
<script src="js/md5.js"></script>

<style type="text/css">
style.header {
	text-align: center;
}

.header h1 {
	font-size: 200%;
	color: #333;
	margin-top: 30px;
}

.header p {
	font-size: 14px;
}

html {
	height: 100%;
}

body {
	margin: 0;
	padding: 0;
	height: 100%;
}

#canvas {
	height: 100%;
}
.date-input{
	padding-right:20px;
	background:url("image/close-3.gif") no-repeat scroll right center transparent;
}
</style>

<script type="text/javascript">


	$(function() {
		var opt=getSessionValue('opt');
		var uid=getQueryString('uid');
		var mid=getQueryString('mid');
		if(uid&&mid){
			var reqData = new RequestData('toRegister.action');
			reqData.merchantid =merchantid;
			reqData.userid=uid;
			var jsonstr = JSON.stringify(reqData);
			$.ajax({
				cache : false,
				type : "POST",
				crossDomain : true,
				url : testUrl,
				data : jsonstr, // 你的formid
				async : false,
				error : function(request) {
					alert("Connection error");
				},
				success : function(data) {
					var dataObj = eval("(" + data + ")");
					if (dataObj.ret == 1) {
						var jsonObj = JSON.stringify(dataObj.params);
						window.sessionStorage.setItem("mdetail", jsonObj);
						window.sessionStorage.setItem("merchantid", merchantid);
						loadMerInfo();
					}
				}
			});
		}else if(opt&&opt=='modify'){
			loadMerInfo();
		}else{
			var mposition=getSessionValue('mposition');
			$("#position").val(mposition);
		}
		doValidate('form');
	});
	var mposition="",mlicenseurl,mphotos=new Array();
	function loadMerInfo(){
		var merchant=getSessionValue('mdetail');
		merchant=JSON.parse(merchant);
		console.log(merchant);
		if(merchant){		
			$("#merchantname").val(merchant.merchantname);
			$("#musername").val(merchant.musername);
			$("#address").val(merchant.address);
			$("#position").val(merchant.position);
			$("#phone").val(merchant.phone);
			$("#spraystation").val(merchant.spraystation);
			$("#daymaxspray").val(merchant.daymaxspray);
			var restway=merchant.restway;
			mposition=merchant.position;
			if(typeof(merchant.restway)=="string"){			
				restway=specialStringToArray(merchant.restway);
			}
			$.each(restway,function(key, value){				
				if(value == '1'){
					$("#restway1").prop('checked',true); 
				}else if(value =='2'){		
					$("#restway2").prop('checked',true); 
				}else if(value =='3'){					
					$("#restway3").prop('checked',true); 
				}
			});
			
			var ct_license='<li id="WU_FILE_0" class="upload-state-done">';
			ct_license+='<img src="'+merchant.licenseurl+'" class="am-thumbnail"></li>';
			$("#licenseurl").append(ct_license);
			var ct_photos="";
			var merchantphotos=merchant.merchantphotos;
			if(typeof(merchant.merchantphotos)=="string"){
				merchantphotos=specialStringToArray(merchant.merchantphotos);
			}		
			$.each(merchantphotos,function(key, value){
				 ct_photos+='<li id="WU_FILE_1'+key+'" class="upload-state-done">';
				ct_photos+='<img src="'+value+'" class="am-thumbnail"></li>';
				
			});
			$("#fileList").append(ct_photos);		
			$("#yearreststartdate").val(merchant.yearreststartdate);
			$("#yearrestenddate").val(merchant.yearrestenddate);
			$("#merchantphotos").val(merchant.merchantphotos);
			mlicenseurl=merchant.licenseurl;
			mphotos=merchantphotos;
		}
	}
	
	function doSubmit(type){
		if($('form').validator('isFormValid')){
			saveToNext(type);
		}
	}
	function saveToNext(type) {	
		popLoading();
		var reqData = new RequestData('register1.action');
		var userid = window.sessionStorage.getItem("userid");
		if (userid) {
			reqData.userid = userid;
		} else {
			popAlert("您尚未登录！");
			userid = "";
			toPage("login.html");
		}
		reqData.userid = userid;
		var merchantid = getSessionValue("merchantid");
		if (merchantid) {
			reqData.merchantid = merchantid;
		} else {
			reqData.merchantid = "";
		}
		reqData.merchantname = $("input[name='merchantname']").val();
		reqData.musername = $("input[name='musername']").val();
		reqData.address = $("input[name='address']").val();
		reqData.position =$("#position").val();
		reqData.phone = $("input[name='phone']").val();
		reqData.spraystation = $("input[name='spraystation']").val();
		reqData.daymaxspray = $("input[name='daymaxspray']").val();
		var values = new Array();
		$("input[name='restway']").each(function() {
			if ($(this).is(":checked")) {
				var value = $(this).val();
				values.push(value);
			}
		});
		reqData.restway = values;
		reqData.yearreststartdate = $("input[name='yearreststartdate']").val();
		reqData.yearrestenddate = $("input[name='yearrestenddate']").val();
		reqData.licenseurl = mlicenseurl;
		reqData.merchantphotos = mphotos;
		var jsonstr = JSON.stringify(reqData);
		$.ajax({
					cache : false,
					type : "POST",
					crossDomain : true,
					url : testUrl,
					data : jsonstr, //你的formid
					async : false,
					error : function(request) {
						closeLoading();
						popAlert("Connection error");
					},
					success : function(data) {
						var dataObj = eval("(" + data + ")");
						if (dataObj.ret == 1) {
							var merchantid = dataObj.params.merchantid;
							window.sessionStorage.removeItem("mposition");
							if (merchantid) {
								window.sessionStorage.setItem("merchantid",merchantid);
							}
							window.sessionStorage.setItem("register1", jsonstr);
							if(type=='snext'){
								location.href = "mregister2.html";
							}else{
								
								popAlert('保存成功!');
							}
							
						}
						closeLoading();
					}
				});
	}
	function toMap(){
	var url = 'baidumap.html';
		var state = {
			url : url
		};
		var title='111';
		history.pushState(state, title, url);//第三个参数url的值将会出现在地址栏
		//location.href = "baidumap.html";
	}

</script>
<style type="text/css">
.am-u-sm-3 lable {
	margin-top: 0.8em;
}

iframe {
	border: none;
}

.ui-icon-posicon:after {
	background-image: url("image/position.png");
	/**你的图片，路径是相对于当前使用文件可以访问到的*/
	background-size: 18px 18px;
	border-radius: 0; /*图标形态，0=方形，不设置就是默认的圆形*/
}
</style>
</head>

<body>
	<header data-am-widget="header" class="am-header am-header-default am-header-fixed">
		<div class="am-header-left am-header-nav">
			<a href="javascript: void(0)"  onclick="javascript:history.back()">
				<i class="am-header-icon am-icon-chevron-left"></i> </a>
		</div>
		<h1 class="am-header-title">
			<a href="#title-link" class=""> 车夫登记1/4 </a>
		</h1>

	</header>
	<div class="am-g" id="pageHome">
		<form class="am-form am-form-horizontal">
			<fieldset>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="merchantname" style="margin-top:0.8em">商户名称</label>
					</div>
					<div class="am-u-sm-9">
						<input type="text" class="am-form-field" name="merchantname"
							id="merchantname" placeholder="商户名称" required>
					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="musername" style="margin-top:0.8em">用户名</label>
					</div>
					<div class="am-u-sm-9">
						<input type="text" class="am-form-field" name="musername"
							id="musername" placeholder="用户名" required>
					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="address">地址</label>
					</div>
					<div class="am-u-sm-9 am-input-group ">
						<input type="text" class="am-form-field" name="address"
							id="address" required placeholder="地址" />
					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="phone">坐标</label>
					</div>
					<div class="am-u-sm-9 am-input-group">
					<input type="text" name="position" id="position" required
						   placeholder="经度,纬度" /> <span
							class="am-input-group-btn am-datepicker-add-on"> <a
							href="baidumap.html" class="am-btn am-btn-default"> <span
							class="am-icon-map-marker"></span> </a> </span>
					</div>

				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="phone">电话</label>
					</div>
					<div class="am-u-sm-9">

						<input type="text" name="phone" id="phone" required
							placeholder="电话" />

					</div>
				</div>

				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="spraystation">喷漆工位</label>
					</div>
					<div class="am-u-sm-9">
						<input type="text" name="spraystation" id="spraystation"
							placeholder="喷漆工位" required class="js-pattern-number" />
					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="daymaxspray">每日最大可喷漆数</label>
					</div>
					<div class="am-u-sm-9">
						<input type="text" name="daymaxspray" id="daymaxspray" required
							class="js-pattern-number" placeholder="每日最大可喷漆数" />
					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label for="restway">休息日</label>
					</div>
					<div class="am-u-sm-9">
						<label class="am-checkbox am-secondary"> <input
							type="checkbox" id="restway1" name="restway" value="1">
							重大节假日休息 </label> <label class="am-checkbox am-secondary"> <input
							type="checkbox" id="restway2" name="restway" value="2">
							周末休息 </label> <label class="am-checkbox am-secondary"> <input
							type="checkbox" id="restway3" name="restway" value="3">春节休息
						</label>
					</div>
				</div>

				<div class="am-form-group">
					<div class="am-u-sm-2">
						<label></label>
					</div>
					<div class="am-u-sm-5 am-input-group date form_datetime-3">
						<input type="text" class="am-form-field "										
						 name="yearreststartdate"
							id="yearreststartdate" placeholder="春节开始日期" data-am-datepicker
							readonly />
					
					</div>
					<div class="am-u-sm-5 am-input-group date form_datetime-3">
						<input type="text" class="am-form-field" name="yearrestenddate"
							id="yearrestenddate" placeholder="春节结束日期" data-am-datepicker
							readonly />

					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label>营业执照</label>
					</div>
					<div class="am-u-sm-9">
						<ul class="am-avg-sm-2 am-avg-md-3 am-avg-lg-4 am-thumbnails"
							id="licenseurl">
						</ul>
						<div id="licensePicker" class="am-form-group am-form-file">
							<i class="am-icon-cloud-upload"></i> 选择执照
						</div>

					</div>
				</div>
				<div class="am-form-group">
					<div class="am-u-sm-3">
						<label>商家照片</label>
					</div>
					<div class="am-u-sm-9">

						<ul class="am-avg-sm-2 am-avg-md-3 am-avg-lg-4 am-thumbnails"
							id="fileList">
						</ul>
						<div id="filePicker" class="am-form-group am-form-file">
							<i class="am-icon-cloud-upload"></i> 选择照片
						</div>

					</div>
				</div>

			</fieldset>

		</form>
		<div class="am-g">
			<div class="am-u-sm-9 am-u-sm-centered">
				<a href="#" class="am-btn am-btn-secondary am-btn-block"
					onclick="doSubmit('snext')">确认无误,进入下一步</a>
			</div>
			<div class="am-u-sm-9 am-u-sm-centered" style="margin-top:0.5em"
				onclick="doSubmit('save')">
				<a href="#" class="am-btn am-btn-secondary am-btn-block">暂时保存</a>
			</div>
		</div>
	</div>
	<div></div>
	<script type="text/javascript" src="js/webuploader.js"></script>
	<script type="text/javascript" src="js/uploader.js"></script>
</body>
</html>
